package com.yyyzzz.servlet;

import com.yyyzzz.bean.Course;
import com.yyyzzz.service.courseService;
import com.yyyzzz.service.impl.courseServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/updateFindOneServlet")
public class updateFindOneServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String courseId = request.getParameter("courseId");
        response.setCharacterEncoding("utf-8");

        courseService service = new courseServiceimpl();
        List courseList0 = service.selectOneById(courseId);
        if (courseList0.size() == 0 ) {
            request.setAttribute("error3", "课程号为：" + courseId + "的课程不存在！！");
            request.getRequestDispatcher("updateCourse.jsp").forward(request, response);
        } else {
            System.out.println(courseList0);
            request.setAttribute("courseList0", courseList0);
            request.getRequestDispatcher("updateCourseInfo.jsp").forward(request, response);
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String courseid = request.getParameter("courseid");
        response.setCharacterEncoding("utf-8");
        courseService service = new courseServiceimpl();
        List courseList0 = service.selectOneById(courseid);
        System.out.println(courseid);
        request.setAttribute("courseList0", courseList0);
        request.getRequestDispatcher("updateCourseInfo.jsp").forward(request, response);

    }
}
